<?php


class WebUserService extends BaseService
{

    private static $self           =   NULL;
    private $mUser                 =   NULL;
    private $mUserMessage          =   NULL;
    private $mUserAward            =   NULL;
    private $mUserTicket           =   NULL;
    private $mDealDeposit          =   NULL;
    private $mUserFund             =   NULL;
    private $mUserLock             =   NULL;
    private $mRefundPlan           =   NULL;
    private $mBankCard             =   NULL;
    private $mExperRecord          =   NULL;
    private $mInvest               =   NULL;
    private $mDealRecord           =   NULL;
    private $mAccrualDay           =   NULL;
    private $mNew                  =   NULL;




    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }
        return self::$self;
    }


    public function __construct()
    {

        $this->mUser                   =   new Involved_UserModel();
        $this->mUserMessage            =   new Involved_UserMessageModel();
        $this->mUserTicket             =   new Involved_UserTicketModel();
        $this->mUserAward              =   new Involved_UserAwardModel();
        $this->mDealDeposit            =   new Involved_DealDepositModel();
        $this->mUserFund               =   new Involved_UserFundModel();
        $this->mUserLock               =   new Involved_UserLockModel();
        $this->mRefundPlan             =   new Involved_RefundPlanModel();
        $this->mBankCard               =   new Involved_BankCardModel();
        $this->mExperRecord            =   new Involved_ExperRecordModel();
        $this->mInvest                 =   new Involved_InvestModel();
        $this->mDealRecord             =   new Involved_DealRecordModel();
        $this->mNew                    =   new Involved_NewsModel();
        $this->mAccrualDay             =   new Involved_AccrualDayModel();
    }

    /**
     * Web投资记录
     * @param $user_id
     * @return mixed
     */
    public function WebInvestRecord($user_id,$page)
    {
        $data = $this->mInvest->WebInvestRecord($user_id,$page);

        if(!empty($data)){
            foreach($data as $k=>$v){
//                if($v->item_status=='COLLECTING'){
//
//                }
                if($v->item_status=='REPAYING'){
                    $v->item_status  =  '计息中';
                }elseif($v->item_status=='FINISHED'){
                    $v->item_status  =  '收益完成';
                }else{
                    $v->item_status  =  '投资成功';
                }

                if(empty($v->repaying_time)){
                    $v->repaying_time = '融满起息';
                }else{
                    $v->repaying_time =  $v->deadline * 86400;
                }

                if($v->award==''){
                    $v->award = 0;
                }
                if($v->rate==''){
                    $v->rate = 0;
                }
                $v->award = $v->award/100;
                $v->rate  = $v->rate/100;
                $v->amount  =   number_format($v->amount/100,2);
                $v->expect_earnings  =  number_format(($v->rate_loaner+$v->rate)*$v->amount*$v->deadline/365/100+$v->award,2);

            }
        }
        return $data;

    }


    /**
     * Web资金流水
     * @param $user_id
     * @param $type
     * @return mixed
     */
    public function WebMoneyRecord($user_id,$type,$page)
    {
        return $this->mDealRecord->WebMoneyRecord($user_id,$type,$page);
    }


    /**
     * 获取个人资金信息
     * @return array
     * @throws Exception
     * @author fyl
     * @data  2016-12-23
     */
    public function WebUserAccounts($user_id)
    {
        #验证登录
        //$user_data = $_SESSION[UserEnum::USER_INFO_SESSION_KEY];
        #返回数据
        // 获取个人资产
        $fund = UserService::instance()->GetFund($user_id);
        // 已激活红包金额
        $awardAmount = $this->mUserAward->AwardAmount($user_id);
        // 已激活加息券
        $ticketInfo = $this->mUserTicket->TicketAmount($user_id);
        //加息劵金额
        $ticketAmount = 0;
        if(!empty($ticketInfo)){
            foreach($ticketInfo as $v) {
                $ticketAmount += $v->rate * $v->amount;
            }
        }
        // 代收本息
        // 回款计划
        $refundPlan = $this->mRefundPlan->RefundPlan($user_id);

        // 等待回款本金
        $waitRefundCapital = 0;
        // 等待回款利息
        $waitRefundAccrual = 0;
        // 已回款利息
        $refundAccrual = 0;
        // 待回款总金额
        $waitRefundTotalAmount = 0;
        // 已回款总金额
        $refundTotalAmount = 0;
        // 等待回款计划
        $waitRefundPlan    = [];
        //体验标
        $TiyanItem = $this->mExperRecord->MonthTiyan($user_id);
        //体验金盈利
        if ($TiyanItem) {
            $TiyanItem = $TiyanItem->return_money;
        } else {
            $TiyanItem = '0';
        }
        $today = strtotime(date('Y-m-d', time()));
        $accrual = 0;
        foreach ($refundPlan as $key => &$value) {
            $value->totalAmount = $value->amount_capital + $value->amount_accrual;
            $value->refund_time_text = date('Y-m-d', $value->refund_time);
            if ($value->status == 0) {
                $waitRefundCapital += $value->amount_capital;
                $waitRefundAccrual += $value->amount_accrual;
                $waitRefundTotalAmount += $value->totalAmount;
            } else {
                $refundTotalAmount += $value->totalAmount;
                $refundAccrual += $value->amount_accrual;
            }

            if($value->refund_time>$today){
                //每天利息
                $day_accrual = $value->amount_accrual/$value->deadline;
                $cha_day = ceil(($today-$value->start_time)/86400);
                $accrual += $day_accrual*$cha_day;
            }
            //dd($oldday,$value->start_time,$today);
        }
        unset($value);

        $myFund = [
            // 可用余额
            'money'         => number_format($fund->money / 100, 2),
            //截止昨日盈利
            'accrual'       => number_format(($refundAccrual + $awardAmount + $TiyanItem +$accrual + $ticketAmount) / 100, 2),
            //总资产
            'totalMoney'    =>number_format(($fund->money + $waitRefundCapital + $waitRefundAccrual + $fund->money_freeze + $ticketAmount) / 100, 2),
            // 待收本金
            'capital'       => number_format($waitRefundCapital / 100, 2),
            // 待收利息
            'accrual_all'   => number_format($waitRefundAccrual / 100, 2),
            // 冻结金额
            'money_freeze' => number_format($fund->money_freeze / 100, 2),
            // 可用余额
            'money_m'         => $fund->money/100,
            //截止昨日盈利
            'accrual_m'       => $refundAccrual + $awardAmount + $TiyanItem +$accrual + $ticketAmount/100,
            //总资产
            'totalMoney_m'    =>($fund->money + $waitRefundCapital + $waitRefundAccrual + $fund->money_freeze + $ticketAmount)/100,
            // 待收本金
            'capital_m'       =>$waitRefundCapital/100,
            // 待收利息
            'accrual_all_m'   => $waitRefundAccrual/100,
            // 冻结金额
            'money_freeze_m' => $fund->money_freeze/100,
        ];
        return $myFund;
    }

    /**
     *累计收益
     */
    public function WebCumulativeProfit($user_id){

        //$user_data = $_SESSION[UserEnum::USER_INFO_SESSION_KEY];
        #返回数据

        // 已激活红包金额
        $awardAmount = $this->mUserAward->AwardAmount($user_id);
        // 已激活加息券
        $ticketInfo = $this->mUserTicket->TicketAmount($user_id);
        //加息劵金额
        $ticketAmount = 0;
        if(!empty($ticketInfo)){
            foreach($ticketInfo as $v) {
                $ticketAmount += $v->rate * $v->amount;
            }
        }
        // 代收本息
        // 回款计划
        $refundPlan = $this->mRefundPlan->RefundPlan($user_id);

        // 等待回款本金
        $waitRefundCapital = 0;
        // 等待回款利息
        $waitRefundAccrual = 0;
        // 已回款利息
        $refundAccrual = 0;
        // 待回款总金额
        $waitRefundTotalAmount = 0;
        // 已回款总金额
        $refundTotalAmount = 0;
        // 等待回款计划
        $waitRefundPlan    = [];
        //体验标
        $TiyanItem = $this->mExperRecord->MonthTiyan($user_id);
        //体验金盈利
        if ($TiyanItem) {
            $TiyanItem = $TiyanItem->return_money;
        } else {
            $TiyanItem = '0';
        }
        $today = strtotime(date('Y-m-d', time()));
        $accrual = 0;
        foreach ($refundPlan as $key => &$value) {
            $value->totalAmount = $value->amount_capital + $value->amount_accrual;
            $value->refund_time_text = date('Y-m-d', $value->refund_time);
            if ($value->status == 0) {
                $waitRefundCapital += $value->amount_capital;
                $waitRefundAccrual += $value->amount_accrual;
                $waitRefundTotalAmount += $value->totalAmount;
            } else {
                $refundTotalAmount += $value->totalAmount;
                $refundAccrual += $value->amount_accrual;
            }

            if($value->refund_time>$today){
                //每天利息
                $day_accrual = $value->amount_accrual/$value->deadline;
                $cha_day = ceil(($today-$value->start_time)/86400);
                $accrual += $day_accrual*$cha_day;
            }
            //dd($oldday,$value->start_time,$today);
        }
        unset($value);

        $accrual_info = $this->mAccrualDay->AccrualInfo($user_id);
        foreach($accrual_info as $k=>&$v){
            $v->accrual = number_format($v->accrual/100,2);
        }
        $myFund = [
            // 累计收益 = 累计已收利息 + 已激活红包 + 代收利息 + 加息券
            'totalAccrual' => number_format(($refundAccrual + $awardAmount + $TiyanItem +$waitRefundAccrual + $ticketAmount) / 100, 2),
            'accrual'      => number_format(($refundAccrual + $awardAmount + $TiyanItem +$accrual + $ticketAmount) / 100, 2),
            'accrual_info' => $accrual_info
        ];

        return $myFund;
    }


    /**
     * 用户邀请码
     * @return mixed
     */
    public function UserInfoInvite($user_id)
    {
        $code =$this->mUser->UserInfoInvite($user_id);
        if(empty($code->invite_code)){
            $invite_code = 0;
        }else{
            $invite_code = $code->invite_code;
        }
        return $invite_code;
    }

    /**
 * 邀请好友人数查询
 * @param $user_id
 * @return mixed
 */
    public function InviteCount($user_id)
    {
        $phase = InviteFriendsEnum::Phase();
        $Last_phase = count($phase)-1;
        $time = [
            $phase[$Last_phase]['start_time'],
            $phase[$Last_phase]['end_time']
        ];
        return $this->mUser->InviteCount($user_id,$time);
    }

    /**
     * 用户邀请已投资人数
     * @return mixed
     */
    public function InvestInviteCount($user_id)
    {
        //获取期
        $phase = InviteFriendsEnum::Phase();
        $Last_phase = count($phase)-1;
        $time = [
            $phase[$Last_phase]['start_time'],
            $phase[$Last_phase]['end_time']
        ];
        //获取被邀请人ID
        $InviteId = $this->mUser->UserInviteId($user_id,$time);
        $count = 0;
        if(!empty($InviteId)) {
            //获取被邀请人ID
            foreach ($InviteId as $v) {
                $userid[] = $v->user_id;
            }
            //获取被邀请人已投资人数
            $count = $this->mInvest->UserInvestCount($userid,$time);
        }
        return $count;
    }

    /**
     * 邀请好友查询
     * @param $user_id
     * @return mixed
     */
    public function WebUserInvite($user_id,$page,$page_size)
    {
        //获取期
        $phase = InviteFriendsEnum::Phase();
        $Last_phase = count($phase)-1;
        $time = [
            $phase[$Last_phase]['start_time'],
            $phase[$Last_phase]['end_time']
        ];
        //获取被邀请人信息
        $info = $this->mUser->ApiUserInvite($user_id,$page,$page_size,$time);
        if(!empty($info)){
            //获取被邀请人ID
            foreach($info as $v){
                $userid[]=$v->user_id;
            }
            //获取邀请人投资记录
            $Invest_id = $this->mInvest->GetInviteInvest($userid,$time);
            //获取投资记录ID
            if(!empty($Invest_id)){
                foreach($Invest_id as $v){
                    $Investid[] = $v->user_id;
                }
                foreach($info as $k=>&$v){
//                    $sub_name = substr($v->user_name,3,6);
//                    $v->user_name = str_replace($sub_name,"****",$v->user_name);
                    if(in_array($v->user_id,$Investid)){
                        $v->status = '已投资';
                    }else{
                        $v->status = '未投资';
                    }
                }
            }else{
                foreach($info as $v){
                    $v->status = '0';
                }
            }
        }
        //判断被邀请人投资状态
        return $info;
    }

    /**
     * @return array
     * @throws Exception
     * 充值
     */
    public function UserAccountsRecharge($user_id){

        // 获取个人资产
        $fund = $this->GetFund($user_id);
        // 充值条件
        $condition = UserEnum::condition();

        $tpldata = [
            // 用户资产
            'fund'      => $fund,
            // 最小充值金额
            'minAmount' => $condition['min_amount'],
        ];
        return $tpldata;
    }

    /**
     * @param $user_id
     * @return bool
     * 根据用户ID取得用户资产数据
     */
    public function GetFund($user_id)
    {
        if (!$user_id)
        {
            return false;
        }

        $fund = $this->mUserFund->GetFund($user_id);

        // 可用余额
        $fund->money = $fund->money_deposit+$fund->money_award+$fund->money_return;

        // 可用余额转换分为元
        $fund->money_unit   = $fund->money/100;
        $fund->money_format = number_format($fund->money/100, 2);
        return $fund;
    }

    /**
     * 支付成功
     */
    public function success($tradeNum)
    {

        // 查询出充值订单
        $trade = DB::table('deal_deposit')
            ->select('auto_id','trade_num','user_id','detail','amount','status')
            ->where('trade_num',$tradeNum)
            ->where('status','WAIT')
            ->first();

        if (!$trade)
        {
            return '支付订单不存在';
        }

        // 资金操作

        $result = DealService::instance()->carry(
        // 用户ID
            $trade->user_id,
            // 总资金
            $trade->amount,
            // 事件ID
            $trade->auto_id,
            // 交易类型
            'IN_DEPOSIT',
            // 交易资金明细
            ['MONEY_DEPOSIT' => $trade->amount],
            // 业务说明
            'DEPOSIT'
        );

        // 发送站内消息
        if ($result == 200)
        {
            // 更新订单状态
            $depositWhere  = [
                'auto_id' => $trade->auto_id,
                'status'  => 'WAIT',
            ];
            $updateDeposit = [
                'status'      => 'SUCCESS',
                'finish_time' => time(),
            ];

            $trade1 = DB::table('deal_deposit')->where($depositWhere)->update($updateDeposit);

            $this->send(
            // 接收者ID
                $trade->user_id,
                // 标题
                '充值成功',
                // 内容
                '尊敬的用户，您已成功充值'.number_format($trade->amount/100, 2).' 元，详情请到账户概况查看。'
            );
        }


        return $result;
    }

    /**
     * 充值判断
     */
    public function _checkDeposit($amount)
    {
        // 检查用户身份证是否认证
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY)->is_idcard)
        {
            return '为保证投资安全，请先完成实名认证';
        }

        // 充值条件
        $condition = UserEnum::condition();
        // 检查充值金额
        if ($amount < $condition['min_amount'])
        {
            throw new Exception('每笔充值金额不少于2元, 并且不能有分、角', 400);
        }

        if ($amount%100 != 0)
        {
            throw new Exception("每笔充值金额不能含有分、角, 您输入的投资金额是".number_format($amount/100, 2)."元", 400);
        }

        if ($amount >= 1000000000)
        {
            throw new Exception('每笔充值金额不能超过 10,000,000 元', 400);
        }

        // 检查充值条件
        $check = UserEnum::check();

        if ($check['status'] != 200)
        {
            throw new Exception('服务器处理错误', 400);
        }

        return 200;
    }

    public function UserDepositRecharge($amount){

        // 检查充值条件
        $result = $this->_checkDeposit($amount);

        // 错误跳转地址
        $redirect = url('/user/deposit/index');

        if ($result != 200)
        {
            throw new Exception("$result", 400);
        }

        // 构建支付表单
        $result = $this->buildTrade(
        // 用户ID
            session_get(UserEnum::USER_INFO_USER_ID),
            // 支付金额
            $amount,
            // 业务说明
            'USER',
            // 是否移动端
            0,
            // 是否使用存管通支付接口
            false
        );

        // 构建失败
        if ($result != 200)
        {
            throw new Exception("$result", 400);
        }

        return $amount/100;
    }


    /**
     * @param $userid
     * @param $amount
     * @param $detail
     * @param bool $isMobile
     * @param bool $isLazycat
     * @return mixed
     * 充值
     */
    public function buildTrade($userid, $amount, $detail, $isMobile = false, $isLazycat = true)
    {
        if (!array_key_exists($detail, StatusEnum::detail()))
        {
            throw new Exception("业务类型错误, 请稍后再试", 400);
        }

        $depositParams = [
            'detail' => '钢票网账户充值',
        ];

        // 固定富友支付
        $payType = 'FUIOU';

        // 移动端使用快捷支付, 否则为网关支付

        if ($isMobile)
        {
            $payWay   = 'SWIFT';
            $bankcard = $this->mBankCard->GetUserBankCard($userid);
            if (!$bankcard)
            {
                return '您的账户还未绑定银行卡';
            }
            $depositParams['bank_code'] = $bankcard->bank_code;
        }
        else
        {

            $payWay  = 'WEB';
        }

        // 创建订单号
        $tradeNum = StatusEnum::buildNumber('DEPOSIT');

        if (!$tradeNum)
        {
            return '订单号创建失败，请稍后再试';
        }
        $bankcard['auto_id'] = '';
        // 构建一张支付订单
        $trade = [
            // 订单号码
            'trade_num'=> $tradeNum,
            // 用户ID
            'user_id'  => $userid,
            // 银行卡ID
            //'bank_id'  => $bankcard['auto_id']?$bankcard['auto_id']:'',
            // 订单金额, 分为单位
            'amount'   => $amount,
            // 支付平台
            'pay_type' => $payType,
            // 支付方式
            'pay_way'  => $payWay,
            // 交易发起端
            'device'   => 'pc',
            // 业务类型
            'detail'   => $detail,
            // 订单状态
            'status'   => 'WAIT',
            // 创建时间
            'add_time' => time(),
        ];


        // 保存订单数据
        $tradeID =  DB::table('deal_deposit')->insertGetId($trade);
        if (!$tradeID)
        {
            return  '订单创建失败, 请稍后再试';
        }

        $trade['auto_id']  = $tradeID;

        //成功
        $fund_s = $this->success($tradeNum);
//        if ($isLazycat)
//        {
//            $payMilleware = \moon\middleware("payment\\Lazycat");
//        }
//        else
//        {
//            // 支付平台
//            $payType = ucfirst(strtolower($payType));
//            $payMilleware = \moon\middleware("payment\\{$payType}");
//        }

//        // 是否移动端
//        $payMilleware->isMobile = $isMobile;
//        // 设置订单
//        $payMilleware->trade    = $trade;
//        // 设置参数
//        $payMilleware->params   = $depositParams;
//
//        // 构建支付
//        $paydata = $payMilleware->build();

        if($fund_s!=200){
            return "$fund_s";
        }
        return 200;
    }


    /**
     * @param $userid
     * @return bool
     * 获取用户银行卡
     */
    public function GetUserBankCard($userid)
    {
        if (!$userid)
        {
            return false;
        }
        return $this->mBankCard->GetUserBankCard($userid);

    }

    /**
     * 我的红包信息
     * @return array
     * @throws Exception
     * @author xf
     * @data  2016-12-26
     */
    public function WebUserAccountsMyred($page)
    {
        if(empty($page)){
            $page=1;
        }
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        $data = $this->mUserAward->WebUserAward($user_id, $page);
        foreach ($data as $v) {
            $v->amount= $v->amount/100;
            $v->restrict_amount= $v->restrict_amount/100;
        }

        $array=array();
        foreach($data as $v){
            if($v->status=='AVAILABLE'||$v->status=='ACTIVATE'){
                $array[] = $v;
            }
        }
        foreach($data as $v){
            if($v->status=='HAS_USED'||$v->status=='PAST_DUE'){
                $array[] = $v;
            }
        }

       return $array;
    }

    /**
     * 实名认证
     * @return array
     * @throws Exception
     * @author xf
     * @data  2016-1-9
     */
    public function WebAuthUserName($paramObj)
    {
        if (empty(session_get(UserEnum::USER_INFO_USER_ID))) {
            $mess['code'] = '2';
            $mess['mess'] = '用户未登录';
            return $mess;
        }
        if (empty($paramObj->name) || empty($paramObj->idcard) || empty($paramObj->banck) || empty($paramObj->phone)) {
            $mess['code'] = '2';
            $mess['mess'] = '参数不足';
            return $mess;
        }
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        $user_data = session_get(UserEnum::USER_INFO_SESSION_KEY);
        if (!preg_match("/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/", $paramObj->idcard)) {
            $mess['code'] = '2';
            $mess['mess'] = '身份证格式不对';
            return $mess;
        }
        //银行卡判断
        if (!preg_match(" /^(\d{16}|\d{19})$/", $paramObj->banck)) {
            $mess['code'] = '2';
            $mess['mess'] = '银行卡号格式不对';
            return $mess;
        }
        if (!preg_match("/^1[34578]{1}\d{9}$/", $paramObj->phone)) {
            $mess['code'] = '2';
            $mess['mess'] = '请输入正确的手机号';
            return $mess;
        }

        $bankshifou= $this->mBankCard->GetUserBankCard($user_id);
        #开始事务
        DB::beginTransaction();
        try {
            $banck = array(
                'telephone' => $paramObj->phone,
                'bank_num' => $paramObj->banck,
                'is_valid' => 1,
                'bank_code' => 'ICBC',
                'add_time' => time(),
                'user_id' => $user_data->user_id
            );
            if(empty($bankshifou)){
                $this->mBankCard->insert($banck);
            }else{
                $this->mBankCard->update($banck, ['user_id' =>$user_id]);
            }
            $userdata = array(
                'name' => $paramObj->name,
                'idcard' => $paramObj->idcard,
                'is_idcard' => 1,
            );
            $this->mUser->update($userdata, ['user_id' => $user_data->user_id]);
            #结束事务
            DB::commit();
            return 1;
        } catch (Exception $e) {
            #事务回滚
            DB::rollback();
            throw $e;
        }

    }

    /**
     * 修改密码
     * @return array
     * @throws Exception
     * @author xf
     * @data  2016-1-9
     */
    public function WebUpdatepwd($paramObj){
        //验证密码还原始密码是不是一样
        $user_info = session_get(UserEnum::USER_INFO_SESSION_KEY);
        $psswd=UserEnum::get(md5(md5($paramObj->oldpwd)),$user_info->salt);//加密方式
        if($psswd!=$user_info->password){
            $mess['code'] = '2';
            $mess['mess'] = '对不起，原密码不对';
            return $mess;
        }
        //新的密码加密
        $salt  =  rand(100000, 999999);
        $newpsswd=UserEnum::get(md5(md5($paramObj->newpwd)),$salt);//加密方式
        $pwddata=array(
            'password'=>$newpsswd,
            'salt'=>$salt,
        );
        $deta= $this->mUser->update($pwddata,['user_id'=>$user_info->user_id]);
        if(!empty($deta)){
            $mess['code'] = '1';
            $mess['mess'] = '修改成功';
            $mess['url'] ='/Web/web_userinstall.html';
            return $mess;
        }else{
            $mess['code'] = '2';
            $mess['mess'] = '修改失败';
            return $mess;
        }
    }
    /**
     *我的消息
     **/
    public function UserAccountsOwnmesg($paramObj){
        if(empty($paramObj->page)){
            $paramObj->page=1;
        }
        if (empty($paramObj->type)) {
           return false;
        }
        //消息
        if($paramObj->type=='message'){
            $user_id=session_get(UserEnum::USER_INFO_USER_ID);
            return $this->mUserMessage->ApiOwnmesg($user_id,$paramObj->page);
        }
        //公告
        if($paramObj->type=='news'){
            return $this->mNew->ApiNewsId($paramObj->page);
        }
    }
    /**
     *我的消息--详情
     **/
    public function WebUserMessageContent($auto_id){
        //消息
            $user_id=session_get(UserEnum::USER_INFO_USER_ID);
            $data = array(
                'is_read'=>1
            );
            $this->mUserMessage->update($data,['user_id'=>$user_id,'auto_id'=>$auto_id]);
            return  $this->mUserMessage->WebOwnmesgCont($user_id,$auto_id);

    }
    /**
     *我的消息--详情
     **/
    public function WebUserUpdateStaue($auto_id){
        //消息
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        $data = array(
            'is_read'=>1
        );
        return $this->mUserMessage->update($data,['user_id'=>$user_id,'auto_id'=>$auto_id]);
    }


    /**
     * 我的加息券
     * @param $page
     * @return mixed
     */
    public function WebUserAccountsTicket($page)
    {
        if(empty($page)){
            $page = 1;
        }
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        $info = $this->mUserTicket->WebUserTicket($user_id,$page);

        foreach($info as $k=>$v){
            foreach(ItemEnum::$Item_types as $kk=>$vv){
                if($v->restrict_item==$kk){
                    $v->restrict_item = '适用'.$vv.'投资项目';
                }
            }
            if($v->status=='IN_USE'){
                $v->status='加息中';
            }elseif($v->status=='AVAILABLE'){
                $v->status='未使用';
            }elseif($v->status='PAST_DUE'){
                $v->status='已失效';
            }else{
                $v->status='已使用';
            }
        }
        return $info;
    }

    /**
     * 我的银行卡
     * @param $page
     * @return mixed
     */
    public function WebUserBankcard($user_id)
    {
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        return $this->mBankCard->WebUserBankCard($user_id);

    }
    /**
     * 我的消息数量
     * @param $page
     * @return mixed
     */
    public  function WebMessageCount(){
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
                return 0;
        }
        return $this->mUserMessage->MessageCount($user_id);


    }
    /**
     * 根据UID查询
     * @param $page
     * @return mixed
     */
    public  function WebUseruserinfo(){
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        return $this->mUser->WebUserInfofirst($user_id);


    }

    /**
     * 根据UId查询银行卡
     * @param $page
     * @return mixed
     */
    public  function WebUnBankCard(){
        $user_id=session_get(UserEnum::USER_INFO_USER_ID);
        return $this->mBankCard->GetUserBankCard($user_id);


    }






}


